package hk.m4s.lr.repair.test.ui.adapter;

import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

import hk.m4s.lr.repair.test.R;
import hk.m4s.lr.repair.test.model.NoticeDeviceModel;
import hk.m4s.lr.repair.test.ui.baoyang.LookBaoYangActivity;

/**
 * Created by qi.wang on 2017/3/27.
 */

public class DeviceRequestsAdapter extends BaseAdapter {
    List<NoticeDeviceModel> list = new ArrayList<>();
    Context context;
    LayoutInflater inflater;

    public DeviceRequestsAdapter(Context context, List<NoticeDeviceModel> data) {
        this.context = context;
        this.list = data;
        inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = inflater.inflate(R.layout.list_item_device_request, parent, false);
            holder.device_title = (TextView) convertView.findViewById(R.id.device_title);
            holder.device_time = (TextView) convertView.findViewById(R.id.device_time);
            holder.device_type = (TextView) convertView.findViewById(R.id.device_type);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        NoticeDeviceModel businessModel=list.get(position);

        try {
            holder.device_title.setText(businessModel.getTitle());
            holder.device_time.setText(businessModel.getSubtime());
            if(businessModel.getState().equals("-1")){
                holder.device_type.setText("未报价");
                holder.device_type.setTextColor(Color.parseColor("#108add"));
            }else if(businessModel.getState().equals("1")){
                holder.device_type.setText("已报价");
                holder.device_type.setTextColor(Color.parseColor("#ff47aa34"));
            }else if(businessModel.getState().equals("2")){
                holder.device_type.setText("已取消");
                holder.device_type.setTextColor(Color.parseColor("#ff2d2d"));
            }else if(businessModel.getState().equals("3")){
                holder.device_type.setText("已完成");
                holder.device_type.setTextColor(Color.parseColor("#777777"));
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return convertView;
    }

    public static class ViewHolder {
        TextView device_title;
        TextView device_time;
        TextView device_type;
    }
}
